package com.topc.code.judge.strategy;

import com.topc.problem.model.code.JudgeInfo;
import com.topc.problem.model.po.ProblemInfo;

import java.math.BigDecimal;
import java.util.Optional;

import static com.topc.code.utils.StrategyUtils.getJudgeInfoResult;

public class JavaLanguageJudgeStrategy implements JudgeStrategy{

    @Override
    public JudgeContext doJudge(JudgeContext judgeContext) {
        System.out.println("============>JAVA DO JUDGE");
        JudgeInfo judgeInfo = judgeContext.getJudgeInfo();
        //获取时间空间消耗
        BigDecimal memory = Optional.ofNullable(judgeInfo.getMemory()).orElse(BigDecimal.valueOf(0));
        BigDecimal time = Optional.ofNullable(judgeInfo.getTime()).orElse(BigDecimal.valueOf(0));
        System.out.println("memory:"+memory+" time:"+time);
        //获取题目基本信息
        ProblemInfo problemInfo = judgeContext.getProblemInfo();
        //获取题目配置信息
        BigDecimal needTimeLimit = problemInfo.getTimeLimit().add(BigDecimal.valueOf(100));
        BigDecimal needMemoryLimit = problemInfo.getMemoryLimit();
        return getJudgeInfoResult(judgeContext,memory, time, needMemoryLimit, needTimeLimit);
    }
}
